package com.lcy.demo;

import org.jboss.resteasy.specimpl.ResponseBuilderImpl;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

/**
 * <p>创建时间：2017/4/17 13:53</p>
 *
 * @author 娄存银
 * @version 1.0
 */
public class CustomExceptionMapper implements ExceptionMapper<CustomException> {

    @Override
    public Response toResponse(CustomException exception) {
        System.out.println("exception handle");
        Response response = new ResponseBuilderImpl()
                .entity(new ResponseData(exception.getCode(),exception.getMessage()))
                .build();
        return response;
    }
    public static class ResponseData{
        private int code;
        private String msg;

        public ResponseData(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }
}
